﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZSZ.DTO;
using ZSZ.IService;
using ZSZ.Model;

namespace ZSZ.Service
{
    public partial class HousePicService : BaseService<HousePic>, IHousePicService
    {
        public void Add(HousePicDTO dto)
        {
            HousePic entity = new HousePic();
            entity.HouseId = dto.HouseId;
            entity.Url = dto.Url;
            entity.ThumbUrl = dto.ThumbUrl;
            Add(entity);
        }

        public HousePicDTO[] GetByHouseId(long houseId)
        {
            return GetAll().Where(hp => hp.HouseId == houseId).ToList().Select(hp=>ToDTO(hp)).ToArray();
        }

        private HousePicDTO ToDTO(HousePic entity)
        {
            HousePicDTO dto = new HousePicDTO();
            dto.CreateDateTime = entity.CreateDateTime;
            dto.Id = entity.Id;
            dto.HouseId = entity.HouseId;
            dto.Url = entity.Url;
            dto.ThumbUrl = entity.ThumbUrl;
            return dto;
        }
    }
}
